<template>
  <div>
    <Title
      minTitle="子账号"
      title="添加子账号"
      introduce="可添加当前组织的子账号，并为其分配权限"
    />
    <div class="form-block">
      <div class="form-msg">
        <el-form
          ref="form"
          :model="sizeForm"
          :rules="rules"
          label-width="85px"
          size="mini"
        >
          <el-form-item label="账号:" prop="account">
            <el-input v-model="sizeForm.account"></el-input>
          </el-form-item>
          <el-form-item label="用户名称:" prop="username">
            <el-input v-model="sizeForm.username"></el-input>
          </el-form-item>
          <el-form-item label="密码:" prop="password">
            <el-input type="password" v-model="sizeForm.password"> </el-input>
          </el-form-item>
          <el-form-item label="确认密码" prop="checkPass">
            <el-input type="confirmpas" v-model="sizeForm.confirmpas">
            </el-input>
          </el-form-item>
          <el-form-item label="类型:" prop="type">
            <el-radio-group
              v-model="sizeForm.type"
              style="width: 200px; line-height: 28px; padding-top: 5px"
            >
              <el-radio label="超级管理员(所有权限)"></el-radio>
              <el-radio label="管理员(拥有部分权限)"></el-radio>
              <el-radio label="观察员(只读权限)"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="账号描述" prop="desc">
            <el-input type="textarea" v-model="sizeForm.desc" :rows="5">
            </el-input>
          </el-form-item>
          <el-form-item size="mini">
            <el-button type="primary" @click="onSubmit"> 确定 </el-button>
            <el-button @click="resetForm('form')">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import Title from "@/components/Title.vue";
import { $addCount } from "@/api/index.js";

export default {
  name: "addusers",
  data() {
    return {
      sizeForm: {
        account: "",
        username: "",
        type: "超级管理员(所有权限)",
        password: "",
        confirmpas: "",
        desc: "",
      },
      rules: {
        account: [{ required: true, message: "请输入账号:", trigger: "blur" }],
        username: [
          { required: true, message: "请输入用户名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入用户密码", trigger: "blur" },
          { min: 8, message: "长度至少8个字符", trigger: "blur" },
        ],
        confirmpas: [
          { required: true, message: "请重复输入用户密码", trigger: "blur" },
          { min: 8, message: "长度至少8个字符", trigger: "blur" },
        ],
        type: [
          {
            required: true,
            message: "请至少选择一个类型",
            trigger: "change",
          },
        ],
        desc: [
          { required: true, message: "请填写您的账号描述", trigger: "blur" },
        ],
      },
    };
  },
  components: {
    Title,
  },
  methods: {
    onSubmit() {
      $addCount(this.sizeForm).then((res) => {
        if (res.data.code == 666) {
          this.$message({
            showClose: true,
            message: "添加成功",
            type: "success",
          });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.form-block {
  width: 100%;
  background-color: #fff;
  padding: 10px 10px 40px 40px;
  .form-msg {
    width: 25%;
  }
}
</style>
